package com.gx.smart.building.ui.warning

import android.view.ViewGroup
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.gx.smart.base.BaseMVVMActivityV3
import com.gx.smart.building.R
import com.gx.smart.building.databinding.ActivityWarningListBinding
import com.gx.smart.building.ui.warning.adapter.PageAdapter
import com.gx.smart.building.ui.warning.viewmodel.WarningViewModel

class WarningListActivity : BaseMVVMActivityV3<WarningViewModel>() {
    private lateinit var viewBinding: ActivityWarningListBinding
    override fun onBindViewModel(): Class<WarningViewModel> = WarningViewModel::class.java

    override fun onBindLayout(): Int = R.layout.activity_warning_list

    override fun getToolbarTitle(): String = "告警列表"

    override fun initContentView(root: ViewGroup) {
        viewBinding = ActivityWarningListBinding.inflate(layoutInflater, root, true)
    }

    override fun onStart() {
        super.onStart()
        val titles = resources.getStringArray(R.array.warning)
        val pagerAdapter = PageAdapter(this)
        viewBinding.viewPager.adapter = pagerAdapter
        viewBinding.viewPager.isUserInputEnabled = true
        TabLayoutMediator(
            viewBinding.tabLayout, viewBinding.viewPager
        ) { tab: TabLayout.Tab, position: Int ->
            tab.text = titles[position]
        }.attach()
//        viewModel.queryAlarmLevelTotal().observe(this) { list ->
//            val titles = resources.getStringArray(R.array.warning)
//            val pagerAdapter = PageAdapter(this)
//            viewBinding.viewPager.adapter = pagerAdapter
//            viewBinding.viewPager.isUserInputEnabled = true
//            TabLayoutMediator(
//                viewBinding.tabLayout, viewBinding.viewPager
//            ) { tab: TabLayout.Tab, position: Int ->
//                tab.text = titles[position] + "(${list[position].quantity})"
//            }.attach()
//        }

    }
}